﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.SqlClient;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
namespace Manager
{
    public partial class frmReport : Form
    {
        SQL sql = new SQL();
        public frmReport()
        {
            InitializeComponent();
        }  
        
        private void btnShow_Click(object sender, EventArgs e)
        {
            
            CrystalReport1 cr = new CrystalReport1();
            DataSet ds = sql.sql_report("sql_select_Info_Report");
            cr.SetDataSource(ds);

            ParameterFieldDefinitions crParameterFieldDefinitions;
            ParameterFieldDefinition crFrom;
            ParameterFieldDefinition crTo;
            ParameterFieldDefinition crMNV;
            ParameterValues crParameterValues = new ParameterValues();
            ParameterDiscreteValue crDiscreteValueFrom = new ParameterDiscreteValue();
            ParameterDiscreteValue crDiscreteValueTo = new ParameterDiscreteValue();
            ParameterDiscreteValue crDiscreteValueMNV = new ParameterDiscreteValue();

            //get values
            crDiscreteValueTo.Value = dateTimeTo.Value.ToShortDateString();
            crDiscreteValueFrom.Value = datetimeFrom.Value.ToShortDateString();
            crDiscreteValueMNV.Value = tbMNV.Text;
            crParameterFieldDefinitions = cr.DataDefinition.ParameterFields;

            crFrom = crParameterFieldDefinitions["dateFrom"];            
            crParameterValues = crFrom.CurrentValues;
            crParameterValues.Clear();
            crParameterValues.Add(crDiscreteValueFrom);
            crFrom.ApplyCurrentValues(crParameterValues);

            crTo = crParameterFieldDefinitions["dateTo"];
            crParameterValues = crTo.CurrentValues;
            crParameterValues.Clear();
            crParameterValues.Add(crDiscreteValueTo);
            crTo.ApplyCurrentValues(crParameterValues);

            crMNV = crParameterFieldDefinitions["MNV"];
            crParameterValues = crMNV.CurrentValues;
            crParameterValues.Clear();
            crParameterValues.Add(crDiscreteValueMNV);
            crMNV.ApplyCurrentValues(crParameterValues);

            crystalReportViewer1.ReportSource = cr;
            crystalReportViewer1.Refresh();
        }

        private void frmReport_Load(object sender, EventArgs e)
        {

        }
        
    }
}
